<template>
  <div v-if="loginUser.name==null">
  <h1>登录 界面</h1>
      
    <el-row>
  <el-col :span="14"><div class="grid-content bg-purple">
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="用户名" prop="name" size="mini" style="width:220px">
    <el-input v-model="ruleForm.name"></el-input>
  </el-form-item>
  <el-form-item label="注侧密码" prop="use" size="mini" style="width:220px">
    <el-input v-model="ruleForm.pwd" ></el-input>
  </el-form-item>

</el-form>
  </div></el-col>
    <el-col :span="10"><div class="grid-content bg-purple-light">
      <el-button type="primary" @click="submitForm('ruleForm')" size="mini">登录</el-button>
      </div></el-col>
</el-row>    
  </div>
</template>

<script>
import {mapState,mapActions,mapMutations} from "vuex"
// import crypto from 'crypto'  
export default {
    computed:{
        ...mapState(["showLogin","loginUser"]),
       
    },
    data(){
        return{
         
            str:{},
            ruleForm:[{
              
            }]
           
        }
    },
    methods:{
    
     async submitForm(){
          var info=await this.ajax.postSubmit("/project/users-bean/login",{name:this.ruleForm.name,pwd:this.ruleForm.pwd});
          this.setUser(info.status)
          alert(JSON.stringify(info))
          
          console.log(info.status==1)
            if(info.status==1){  
        this.$cookies.set("token",info.data.token);
        this.$cookies.set("refreshToken",info.data.refreshToken);
         this.$cookies.set("there",info.data.theretoken);

        this.$router.push("/index");  
        this.setUser(info.data.user);
                 this.$message({
          showClose: true,
          message: '恭喜你，登录成功',
          type: 'success',
           center: true
        });
        
    location.href="/index"
        this.findProductByItem()
        // alert( JSON.stringify(this.userList))
          this.setShowLogin(false)
            }else{
                 this.$message({
          showClose: true,
          message: '警告，添加失败',
          type: 'error',
           center: true
        });       
               
            }
       
     },
         ...mapMutations(["setShowLogin","setUser"]),
        ...mapActions(["findProductByItem","getUsers"]),

    },
     

}
</script>

<style>

</style>